<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="/layuimini/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
  <div class="layuimini-main">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
      <legend>账号</legend>
    </fieldset>
  </div>
  <form id="metaObject" class="layui-form" action="" method="">
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">账号名称</label>
        <div class="layui-input-inline">
          <input type="text" name="userName" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
          <input type="password" name="password" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
        </div>
      </div>

    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit="" lay-filter="account"  >立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
    </div>

  </form>
</div>
<script src="/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/layuimini/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>

<script>
  layui.use(['form','jquery'],function () {
    var form = layui.form,
            layer = layui.layer;
    form.render();

    form.on('submit(account)',function (data) {
      $.ajax({
        type:'post',
        url:'/account/add',
        data:data.field,  //重点必须为一个变量如：data
        dataType:'json',
        success:function(res){
          //layer.alert(JSON.stringify(res));

          var index = layer.alert(JSON.stringify(res), {
            title: '最终的提交信息'
          });

          var iframeIndex = parent.layer.getFrameIndex(window.name);
          parent.location.reload();
          parent.layer.close(iframeIndex);

        },
        error:function(){
          layer.alert(JSON.stringify('失败'));
        }
      });
      return false;
    });

  });
</script>

</body>
</html>